const message = require('../model/returnMessage');
const {
  getReplyListOfComment,
  getReplyById,
  addReply,
  likeReply,
  unlikeReply,
  deleteReply
} = require('../model/reply');

module.exports.getReplyListOfComment = async (req, res, next) => {
  getReplyListOfComment(req.params.id).then(
    (r) => {
      res.status(200).json(message(r, 'Get replyList.'));
    },
    (e) => {
      res.status(500).json(message(e, 'Internal server error.'));
    }
  );
};

module.exports.getReplyById = async (req, res, next) => {
  getReplyById(req.params.id).then(
    (r) => {
      res.status(200).json(message(r, 'Get reply.'));
    },
    (e) => {
      res.status(500).json(message(e, 'Internal server error.'));
    }
  );
};

module.exports.addReply = async (req, res, next) => {
  addReply(req.body).then(
    (r) => {
      res.status(201).json(message(req.body, 'Reply created.'));
    },
    (e) => {
      res.status(500).json(message(e, 'Internal server error.'));
    }
  );
};

module.exports.likeReply = async (req, res, next) => {
  likeReply(req.params.id).then(
    (r) => {
      res.status(201).json('Reply liked.');
    },
    (e) => {
      res.status(500).json(message(e, 'Internal server error.'));
    }
  );
};

module.exports.unlikeReply = async (req, res, next) => {
  unlikeReply(req.params.id).then(
    (r) => {
      res.status(201).json('Reply unliked.');
    },
    (e) => {
      res.status(500).json(message(e, 'Internal server error.'));
    }
  );
};

module.exports.deleteReply = async (req, res, next) => {
  deleteReply(req.params.id).then(
    (r) => {
      res.status(200).json(message(r, 'Reply deleted.'));
    },
    (e) => {
      res.status(500).json(message(e, 'Internal server error.'));
    }
  );
};
